<?php
/**
 * Load kiwi.php
 */
$kiwiHome = dirname(dirname(dirname(dirname(__FILE__))));
include($kiwiHome . DIRECTORY_SEPARATOR . 'runtime' . DIRECTORY_SEPARATOR . 'kiwi.php');

/**
 * Retrive the client's request data
 */
$operation = 'query';
$opcodeCacheExt = isset($_REQUEST['opcode_cache_ext']) ? $_REQUEST['opcode_cache_ext'] : null;
$cacheKey = $_REQUEST['cache_key'];
if (isset($_REQUEST['data_to_cache']))
{
	$dataToCache = unserialize($_REQUEST['data_to_cache']);
	$operation = 'rebuild';
}

/**
 * Get opcade cache adapter instance
 */
KiwiSystemCache::$opcodeCacheInstance = $opcodeCacheExt ? OpcodeCacheAdapterFactory::factory($opcodeCacheExt) : OpcodeCacheAdapterFactory::factory();

if ('rebuild' == $operation)
{
	KiwiSystemCache::$opcodeCacheInstance->delete($cacheKey);
	KiwiSystemCache::$opcodeCacheInstance->add($cacheKey, $dataToCache);
	echo "cache added: $cacheKey\n";
}
else if ('query' == $operation)
{
	echo "Content of opcode cache: $cacheKey\n";
	print_r(KiwiSystemCache::$opcodeCacheInstance->get($cacheKey));
}